//
//  InComeCell.m
//  村医
//
//  Created by Mac on 2017/6/7.
//  Copyright © 2017年 WX. All rights reserved.
//

#import "InComeCell.h"
#import <Masonry.h>
#import "NSAttributedString+Extension.h"
#import "NSDate+YCUse.h"
#define kPadding 10

static NSString *cellId = @"InComeCell";


@interface InComeCell()

@property(nonatomic,weak)UILabel *timeLabel;
@property(nonatomic,weak)UILabel *nameLabel;
@property(nonatomic,weak)UILabel *moneryLabel;
@property(nonatomic,weak)UILabel *desLabel;


@end
@implementation InComeCell

+(instancetype)inComeCellWithTabelView:(UITableView *)tableView {
    
    InComeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    if (cell==nil) {
        cell = [[InComeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
        [self configSubviews];
    }
    
    return  self;

}


-(void)configSubviews {
    

    UILabel *timeLabel = [[UILabel alloc]init];
    
    self.timeLabel = timeLabel;
    
    timeLabel.font = [UIFont systemFontOfSize:16];
    
    [self.contentView addSubview:timeLabel];
    
    UIView *backView = [[UIView alloc]init];
    
    backView.backgroundColor = [UIColor colorWithCommonType:CommonColorSubFCGray];
    
    [self.contentView addSubview:backView];
    
    UILabel *nameLabel = [[UILabel alloc]init];
    
    self.nameLabel = nameLabel;
    
    nameLabel.textColor = [UIColor grayColor];
    
    [backView addSubview:nameLabel];
    
    UILabel *moneryLabel = [[UILabel alloc]init];
    
    self.moneryLabel = moneryLabel;
    
    moneryLabel.textColor = [UIColor grayColor];
    
    [backView addSubview:moneryLabel];
    
    UILabel *desLabel = [[UILabel alloc]init];
    
    self.desLabel = desLabel;
    
    desLabel.textColor = [UIColor grayColor];
    
    desLabel.numberOfLines = 0;

    [backView addSubview:desLabel];
    
    UIView *bottomLineView = [[UIView alloc]init];
    
    bottomLineView.backgroundColor =[UIColor colorWithCommonType:CommonColorSeparate];
    
    [self.contentView addSubview:bottomLineView];
    
    //设置假数据
    timeLabel.text = @"";
    
    nameLabel.text = @"保障人:";
    
    moneryLabel.attributedText = [NSMutableAttributedString zj_attributeStringWithPrefixString:@"提成金额:" prefixFont:16 prefixColor:[UIColor grayColor] suffixString:@" " suffixFont:16 suffixColor:[UIColor colorWithCommonType:CommonColorBlue]];
    
    desLabel.text = @"提成明细:";

    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(kPadding);
        
        make.left.mas_equalTo(20);
        
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
         make.top.mas_equalTo(backView).offset(kPadding);
        
         make.left.mas_equalTo(backView).offset(20);
        
    }];
    
    [moneryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(backView).offset(15);
        
        make.top.mas_equalTo(nameLabel.mas_bottom).offset(kPadding);
    }];
    
    [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(backView).offset(15);
        
        make.right.mas_equalTo(backView).offset(-20);
        
        make.top.mas_equalTo(moneryLabel.mas_bottom).offset(kPadding);
        
        make.bottom.mas_equalTo(backView.mas_bottom).offset(-20);
    }];
    
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.contentView);
        
        make.top.mas_equalTo(timeLabel.mas_bottom).offset(kPadding);
 
    }];
    
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView.mas_bottom).offset(15);
        
        make.left.right.equalTo(self.contentView);
        
        make.height.mas_equalTo(0.5);
        
        make.bottom.mas_equalTo(self.contentView);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.bottom.equalTo(self);
        
    }];

}
-(void)setModel:(AchievementViewModel *)model{
    
    _model = model;
    
    NSLog(@"%@",model.CREATE_DATE);
    
    NSString *timeStr = [NSDate zj_weekDayfromCreatedDate:model.CREATE_DATE];
    
    self.timeLabel.text = timeStr;
    
    self.nameLabel.text = [NSString stringWithFormat:@"保障人: %@",model.PERSON_NAME];
    
    self.moneryLabel.attributedText = [NSMutableAttributedString zj_attributeStringWithPrefixString:@"提成金额: " prefixFont:16 prefixColor:[UIColor grayColor] suffixString: model.TAKE_MONEY suffixFont:16 suffixColor:[UIColor colorWithCommonType:CommonColorBlue]];
    
    self.desLabel.text = [NSString stringWithFormat:@"提成明细: %@", model.TAKE_DESC];
    

}

@end
